<%
   String error = request.getParameter( "error" );
   Boolean logged = false;
   session.setAttribute( "Logged", logged );
%>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

<head>

<link rel="stylesheet" href="images/UrbanArtist.css" type="text/css" />

<!-- <script src="jquery.js" type="text/javascript" charset="utf-8"></script> -->
<script src="jquery-1.3.1.min.js"></script>
<script src="jquery-ui-1.7.custom.min.js"></script>

<script src="jquery.valid8.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
	// some documentation on using the valid8 plugin
	// http://www.unwrongest.com/projects/valid8/

	$("#login").click(function(){login()});
	
	// checks username boxes for validity using the valid8 plugin
	// code must remain in "$(document).ready(function(){" area
	$('#inputUsername').valid8({
		reguglarExpressions: [
			{expression: /^.+$/, errormessage: 'Error: Username is required.'},
			{expression: /^([a-zA-Z0-9])+$/, errormessage: 'Error: Username must consist of only letters and numbers.'}
		]
	});
	
	// checks password boxes for validity using the valid8 plugin
	// code must remain in "$(document).ready(function(){" area
	$('#inputPassword').valid8({
		reguglarExpressions: [
			{expression: /^.+$/, errormessage: 'Error: Password is required.'},
			{expression: /^([a-zA-Z0-9])+$/, errormessage: 'Error: Password must consist of only letters and numbers.'}
		],
	});

		
});	// end $(document).ready(function(){

	
	// LOGIN BUTTON
	function login(){
		if ($('input').isValid() == true) {
			var clientid = $("#inputUsername")[0].value;
			var password = $("#inputPassword")[0].value;
			var loginurl = "http://tornado.ics.uci.edu:8080/pimp/WebResponder?&type=login&loginID="+clientid+"&password="+password;
		
			$.get(loginurl, function(data){

				// if 1 is returned... we forward to new site
				if (data == 1) {
					// set var to true
					
					<%
						logged = true;
						session.setAttribute( "Logged", logged );
		
						String sessionID = session.getId();
						session.setAttribute("ID", sessionID);
						
					%>
					
					// redirect to im.jsp
					location.href="im.jsp?&id="+clientid;

				} else {
					alert("Invalid username/password.  Error Code: " + data);
				}
				
				// otherwise dont forward
				
			});
		} else if ($('input').isValid() == false) {
			alert('ERROR: Invalid input, please reenter your login according to the listed requirements.');
		}
	}


	
</script>

<title>pIMp: Homepage</title>
</head>

<body>

<!-- wrap starts here -->
<div id="wrap">

	<!--header -->
	<div id="header">			
		
		<!--
		<h1 id="logo-text"><a href="index.jsp" title="">pIMp</a></h1>		
		<p id="intro">personal Instant Messaging plus</p>
		-->
		
		<div  id="nav">
			<ul>
				<li id="current"><a href="index.jsp">Home</a></li>
				<li><a href="register.jsp">Register</a></li>
				<li><a href="downloads.jsp">Downloads</a></li>
			</ul>		
		</div>	
						
	<!--header ends-->					
	</div>
	
	<!-- content-wrap starts -->
	<div id="content-wrap">
				
		<div id="main">
				
			<a name="TemplateInfo"></a>
			<h2><a href="index.jsp">About</a></h2>
				
			<p><strong>pIMp</strong> stands for personal Instant Messaging plus and it is a project created during the winter 
			quarter of 2009 at UCI for Informatics 122.</p>  

			<p>If you don't have an accont, you will need to register (for free) <a href="register.jsp">here.</a></p>
			
			<p>You can download the standalone version of <strong>pIMp</strong> <a href="downloads.jsp">here.</a></p>
	

			<br>
			<blockquote>
			<p>To be yourself in a world that is constantly trying to 
			make you something else is the greatest accomplishment.
			</p>
		
			<p class="align-right"> - Ralph Waldo Emerson</p>
			</blockquote>

			
		<!-- main ends -->	
		</div>
		
		<!-- sidebar starts -->
		<div id="sidebar">			
		
			<h3>Login (web client)</h3>
			<!-- <form method="post" action="im.jsp"> -->
			
			<p>
				<label for="inputUsername">Login Username:</label>
				<input type="text" value="" name="inputUsername" id="inputUsername"/>
			</p>
			
			<p>
				<label for="inputPassword">Login Password:&nbsp;</label>
				<input type="password" name="inputPassword" id="inputPassword">
			</p>
			
			<p align="center"><button id="login">Login</button></p>
			<!-- </form> -->
			
			<br>
			<center><i><b><a href="register.jsp" style="font-size: 16px;">Or Click Here to Register!</a></b></i></center>
			

			<h3>Navigation Menu</h3>
			<ul class="sidemenu">	
				<li><a href="register.jsp">Register</a></li>
				<li><a href="downloads.jsp">Downloads</a></li>
			</ul>
	
			<h3>Creators</h3>
			<ul class="sidebar">
					<li><strong><u>Team 2</u></strong></li>
					<li>Chad Curtis</li>
    				<li>Scott Ditch</li>
    				<li>Robert Duncan</li>
    				<li>Alexander Doan</li>
    				<li>Matt Fritz</li>
    				<li>Robert Jolly</li>
    				<li>Alex Kaiser</li>
    				<li>Dan Morgan</li>
    				<li>Scott Roeder</li>
    				<li>James Rose</li>
				    <li>David Schramm</li>
					<li>Jordan Sinclair</li>
					<li>Josh Villamarzo</li>
			</ul>
			
		<!-- sidebar ends -->		
		</div>
		
	<!-- content-wrap ends-->	
	</div>

	<!-- footer starts here -->	
	<div id="footer">
	
		<div id="footer-left">
			<p>
			Template Design by: <a href="http://www.styleshout.com/">styleshout</a>	&nbsp; 
			</p>	
		</div>
		
		<div id="footer-right">
			<p class="align-right">
			<a href="index.jsp">Home</a> | <a href="http://www.ics.uci.edu/~andre/informatics122w2009.html">Class Site</a>
			</p>
		</div>
		
	</div>
	<!-- footer ends here -->
	
<!-- wrap ends here -->
</div>

</body>
</html>
